package com.fengdi.everyday.hard;


/**
 * @Description 1611 使整数变为0的最小操作次数
 * @Date 09:51
 */
public class MinimumOneBitOperations {

    // 纯数学题
    public int minimumOneBitOperations(int n) {
        if (n == 0) {
            return 0;
        }
        int x = Integer.toBinaryString(n).length() - 1;
        return (1 << (x + 1)) - 1 - minimumOneBitOperations(n - (1 << x));
    }
}
